package com.sdry.web.controller.hpf;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.hpf.CacheAreaOut;
import com.sdry.model.hpf.Page;
import com.sdry.service.hpf.CacheAreaOutService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * @ClassName: CacheAreaOutController 
 * @Description:缓存区出库Controller
 * @Author hpf
 * @Date 2018年9月19日 上午11:44:31 
 * @version 1.0
 */
@Controller
@RequestMapping(value="/cacheAreaOut")
public class CacheAreaOutController {

	@Resource
	private CacheAreaOutService cacheAreaOutService;
	
	/**
	 * 分页查询缓存区出库
	 * @param page 分页条件
	 * @param cacheAreaOut 查询条件
	 * @param response
	 */
	@RequestMapping(value="/listPageCacheAreaOut")
	public void listPageCacheAreaOut(Page page,CacheAreaOut cacheAreaOut,HttpServletResponse response){
		Map<String, Object> map = new HashMap<>();
		map.put("page", page.getPage());
		map.put("limit", page.getLimit());
		if (cacheAreaOut.getPanum() != null) {
			map.put("panum", cacheAreaOut.getPanum());
		} else {
			map.put("panum", "");
			cacheAreaOut.setPanum("");
		}
		List<CacheAreaOut> cacheAreaOutList = cacheAreaOutService.listPageCacheAreaOut(map);
		int count = cacheAreaOutService.countCacheAreaOut(cacheAreaOut);
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(cacheAreaOutList, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);
		jsonObject.put("count", count);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
